package trading;


public class Parameters 
{
	private Parameter[] params; 
	
	/**
	 * initValue should be int[][4] (max, min, default, step)
	 * @param initValues 
	 */
	public Parameters(int[][] initValues)
	{
		params = new Parameter[initValues.length];
		for (int i = 0; i < initValues.length; i++) {
			int[] values = initValues[i];
			if(values.length != 4)
			{
				throw new IllegalArgumentException("invalid paramter length!");
			}
			params[i] = new Parameter(values);
		}
	}
	
	public int getParamSize()
	{
		return params.length;
	}
	
	public void setParamValue(int index, int value)
	{
		Parameter param = params[index];
		param.setValue(value);
	}
	
	public int getParamValue(int index)
	{
		Parameter param = params[index];
		return param.getValue();
	}
	
	public Parameter getParameter(int index)
	{
		return params[index];
	}
	
	public String getParamsAsKey()
	{
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < params.length; i++) {
			Parameter param = params[i];
			sb.append(param.getValue());
			if(i != params.length - 1)
				sb.append("_");
		}
		return sb.toString();
	}
	
	static public class Parameter
	{
		private int paramMaxVal;
		private int paramMinVal;
		private int paramStep;
		private int value;
		
		public Parameter(int[] values)
		{
			this.paramMaxVal = values[0];
			this.paramMinVal = values[1];
			this.value = values[2];
			this.paramStep = values[3];
		}
		
		public int getParamMaxVal() {
			return paramMaxVal;
		}
		public int getParamMinVal() {
			return paramMinVal;
		}
		public int getParamStep() {
			return paramStep;
		}
		
		public void setValue(int val)
		{
			this.value = val;
		}
		
		public int getValue() {
			return value;
		}

		public void setParamMaxVal(int paramMaxVal) {
			this.paramMaxVal = paramMaxVal;
		}

		public void setParamMinVal(int paramMinVal) {
			this.paramMinVal = paramMinVal;
		}

		public void setParamStep(int paramStep) {
			this.paramStep = paramStep;
		}
	}
}
